package com.sgl.config.shiro;

import com.sgl.entity.User;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.crypto.hash.SimpleHash;

public class ShiroUtil {


	/**
	 * 加密算法
	 */
	public final static String hashAlgorithmName = "SHA-256";
	/**
	 * 循环次数
	 */
	public final static int hashIterations = 16;

	public static String sha256(String password, String salt) {
		return new SimpleHash(hashAlgorithmName, password, salt, hashIterations).toString();
	}

	public static User getUser() {
		return (User) SecurityUtils.getSubject().getPrincipal();
	}

	public static Long getUserId() {
		return getUser().getId();
	}





	public static void main(String[] args) {

		//sha256加密
//		String salt = RandomStringUtils.randomAlphanumeric(20);
//		System.out.println(salt);
//
//		System.out.println(sha256("123456",salt));

		int[] nums1 = {2, 0, 5, 0, 1, 0, 0, 0};
		//1.2.3.5       j=0    i=0   count=1  3
		//1.2.2.3.5     j=1    i=2   count=2  2
		// 1 2 2 2 3 5  j=2    i=3   count=3  2
		//1,
		int[] nums2 = {0, 0, 1};

		//i=0  j=0   4  1 0 3 12


//		for (int i=0;i<nums.length;i++){
//			System.out.println(nums[i]);
//		}
	}

}



